﻿Imports System.Collections.Generic

Public Class UCOrdena(Of T)
    Implements IComparer(Of T)
    Private Criterio As String
    Private Ascendente As Boolean = True

    Public Sub New(ByVal mCriterio As String, ByVal mAscendente As Boolean)
        Criterio = mCriterio
        Ascendente = mAscendente
    End Sub

    Public Function Comparar(ByVal x As T, ByVal y As T) As Integer Implements System.Collections.Generic.IComparer(Of T).Compare
        Dim valX As Object = x.GetType.GetProperty(Criterio).GetValue(x, Nothing)
        Dim valY As Object = y.GetType.GetProperty(Criterio).GetValue(y, Nothing)
        Dim N As Integer
        If Ascendente Then
            N = valX.CompareTo(valY)
        Else
            N = valY.CompareTo(valX)
        End If
        Return (N)
    End Function
End Class